﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DatabaseModule;

namespace EMC
{
    public class FriendManagement
    {
        private DAO dbConn;

        private databaseConfiguration config;

        public FriendManagement(databaseConfiguration dbConfig)
        {
            this.config = dbConfig;
            dbConn = dbFactory.newDB(config.dbType, config.dbConnectionString);
        }

        public List<string> ListFriends(string userid)
        {
            KeyValues keyValsMeFirst = new KeyValues();
            keyValsMeFirst.Add(config.tableFriends_UserID1, userid);
            List<Dictionary<string, string>> meFirst = dbConn.GetRows(config.tableFriends, new string[] { config.tableFriends_UserID2 }, keyValsMeFirst);

            KeyValues keyValsMeSecond = new KeyValues();
            keyValsMeSecond.Add(config.tableFriends_UserID2, userid);
            List<Dictionary<string, string>> meSecond = dbConn.GetRows(config.tableFriends, new string[] { config.tableFriends_UserID1 }, keyValsMeSecond);
            
            List<string> friends = meFirst.ConsolidateValues(config.tableFriends_UserID2);
            friends.AddRange(meSecond.ConsolidateValues(config.tableFriends_UserID1));
            

            return friends;
        }
        public bool checkfriend(string userid)
        {

            return true;
        }
    }
}
